﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace jnagr.Web
{
    public partial class LoginService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["loginId"]))
                {
                    string uid = Request["loginId"];

                    jnagr.BLL.userinfo u = new BLL.userinfo();
                    DataSet um = u.LoginData(int.Parse(uid));
                    if (um.Tables[0].Rows.Count == 1)
                    {
                        jnagr.Model.userinfo userModel = u.Login(int.Parse(uid));
                        Session["user"] = um.Tables[0];
                        Session["UserInfo"] = userModel;
                        //if (chkpwd.Checked)
                        //{
                        //    HttpCookie userCookie = new HttpCookie("UserInfo");
                        //    userCookie.Expires = DateTime.Now.AddDays(15);
                        //    userCookie["UserID"] = jnxc.Common.DEncrypt.DESEncrypt.Encrypt(userModel.uid.ToString());
                        //    userCookie["DisplayName"] = jnxc.Common.DEncrypt.DESEncrypt.Encrypt(userModel.utruename);
                        //    userCookie["LoginName"] = jnxc.Common.DEncrypt.DESEncrypt.Encrypt(userModel.uname);
                        //    userCookie["Password"] = jnxc.Common.DEncrypt.DESEncrypt.Encrypt(userModel.upwd);
                        //    userCookie["Remark"] = jnxc.Common.DEncrypt.DESEncrypt.Encrypt(userModel.remark);
                        //    Response.Cookies.Add(userCookie);
                        //}
                        Response.Redirect("Main.aspx");
                    }
                    else
                    {
                        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('用户名或密码错误！请重新登录！')", true);
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript",
                                   "<script>alert('用户名或密码不正确');history.go(-1);</script>");
                    }
                }

            }
        }
    }
}